package com.example.mall.web.controller;

import com.example.mall.domain.OrderPayments;
import com.example.mall.dto.OrderPaymentsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.OrderPaymentsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IOrderPaymentsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderPayments")
public class OrderPaymentsController {

    @Autowired
    public IOrderPaymentsService orderPaymentsService;

    /**
     * 分页查询订单支付记录表信息
     * @param orderPaymentsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询订单支付记录表信息",notes = "分页查询订单支付记录表信息",httpMethod = "GET")
    public JSONResult queryPage(OrderPaymentsQuery orderPaymentsQuery){
        PageDTO<OrderPaymentsDto> orderPaymentsDtoPageDTO = orderPaymentsService.queryPage(orderPaymentsQuery);
        return JSONResult.success("查询成功",orderPaymentsDtoPageDTO);
    }

    /**
     * 根据id查询订单支付记录表信息
     * @param paymentId
     * @return
     */
    @GetMapping("query/{paymentId}")
    @ApiOperation(value = "根据id查询订单支付记录表信息",notes = "根据id查询订单支付记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("paymentId")Long paymentId){
        //1.根据id查询用户信息
        if (paymentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAYMENTID_NOT_ID);
        }
        OrderPayments orderPayments = orderPaymentsService.getById(paymentId);
        return JSONResult.success("查询成功",orderPayments);
    }

    /**
     * 根据id查询订单支付记录表信息
     * @param paymentId
     * @return
     */
    @GetMapping("queryOrderPaymentsById/{id}")
    @ApiOperation(value = "根据id查询订单支付记录表信息",notes = "根据id查询订单支付记录表信息",httpMethod = "GET")
    public JSONResult queryOrderPaymentsById(@PathVariable("paymentId")Long paymentId){
        //1.根据id查询用户信息
        if (paymentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAYMENTID_NOT_ID);
        }
        OrderPayments orderPayments = orderPaymentsService.queryOrderPaymentsById(paymentId);
        return JSONResult.success("查询成功",orderPayments);
    }

    /**
     * 查询全部订单支付记录表信息
     * @param
     * @return
     */
    @GetMapping("queryOrderPaymentsList")
    @ApiOperation(value = "查询全部订单支付记录表信息",notes = "查询全部订单支付记录表信息",httpMethod = "GET")
    public JSONResult queryOrderPaymentsList(){
        List<OrderPayments> logins = orderPaymentsService.queryOrderPaymentsList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增订单支付记录表
     * @param orderPaymentsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增订单支付记录表",notes = "新增订单支付记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody OrderPaymentsDto orderPaymentsDto){
        orderPaymentsService.insert(orderPaymentsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改订单支付记录表信息
     * @param orderPaymentsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改订单支付记录表信息",notes = "修改订单支付记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody OrderPaymentsDto orderPaymentsDto){
        orderPaymentsService.update(orderPaymentsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除订单支付记录表信息
     * @param paymentId
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除订单支付记录表信息",notes = "删除订单支付记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("paymentId") Long paymentId) {
        orderPaymentsService.delete(paymentId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除订单支付记录表信息
     * @param paymentIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除订单支付记录表信息",notes = "批量删除订单支付记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> paymentIds) {
        orderPaymentsService.deleteBatch(paymentIds);
        return JSONResult.success("批量删除成功");
    }
}
